package cn.jinjimi.app.entity.Item;

import cn.jinjimi.base.util.StringUtils;
import cn.jinjimi.app.entity.Material;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Roy
 * Date: 2017/4/11
 */

public class HomeMaterialItem {

    public Material material;

    public boolean isFirst;

    public int type;

    public static final int TypeArticle = 0;
    public static final int TypePoster = 1;
    public static final int TypeLogon = 2;

    public static List<HomeMaterialItem> createMaterialItem(List<Material> materials) {
        List<HomeMaterialItem> homeMaterialItems = new ArrayList<>();
        if (materials != null) {
            for (int i = 0, j = materials.size(); i < j; i++) {
                Material material = materials.get(i);
                int type = getType(material.type);
                if (type == -1)
                    continue;

                HomeMaterialItem homeMaterialItem = new HomeMaterialItem();
                homeMaterialItem.material = materials.get(i);
                homeMaterialItem.type = type;

                if (i == 0)
                    homeMaterialItem.isFirst = true;

                homeMaterialItems.add(homeMaterialItem);
            }
        }

        return homeMaterialItems;
    }

    public static int getType(String typeStr) {
        if (StringUtils.isEmpty(typeStr))
            return -1;

        int type = -1;
        switch (typeStr) {
            case Material.TypeArticle:
                type = TypeArticle;
                break;
            case Material.TypePoster:
                type = TypePoster;
                break;
            case Material.TypeLogion:
                type = TypeLogon;
                break;
        }

        return type;
    }
}
